/*
 *  fresnel.c
 *  AutoEllips
 *
 *  Created by Simon Martin on 09/11/2009.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include "fresnel.h"


double degreesToRadians (double degrees)
{
	return (M_PI*degrees/180.);
}

double complex cos_snell(double complex n1, double complex n2, double complex angle)
{
	//uses a combination of Snell's law and 1=cos^2+sin^2 to calculate the cosine of the incident angle in the given media
	return(csqrt(1.0-cpow(csin(angle)*(n1/n2),2.)));
	
}
double complex snell(double complex n1, double complex n2, double  angle)
{
	return (casin((n1/n2)*csin(angle)));// snell's law	
}


double complex rp(double complex n1, double complex n2, double  complex cangle1, double  complex cangle2)
{
	// calculates the fresnel term rp
	// the cangle variables are the cosines of the angles.
	return ((n2*cangle1-n1*cangle2)/(n2*cangle1+n1*cangle2));
}

double complex rs(double complex n1, double complex n2, double complex cangle1, double complex cangle2)
{
	// calculates the fresnel term rs
	// the cangle variables are the cosines of the angles.
	return ((n1*cangle1-n2*cangle2)/(n1*cangle1+n2*cangle2));
}

